package multithreaded;

import java.util.Random;

public class ThreadSample1 {
    class Runner extends Thread {
        @Override
        public void run() {
            int speed = new Random().nextInt(10);
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("第" + (i + 1) + "秒" + this.getName()
                        + "已跑到" + (i * speed) + "米(" + speed + "米/秒)");
            }
        }
    }

    public void start() {
        Runner threadA = new Runner();
        threadA.setName("参赛者A");

        Runner threadB = new Runner();
        threadB.setName("参赛者B");

        Runner threadC = new Runner();
        threadC.setName("参赛者C");

        threadA.start();
        threadB.start();
        threadC.start();
    }


    public static void main(String[] args) {
        new ThreadSample1().start();
    }
}
